package com.cymal.search.subject;

import com.cymal.entity.po.answer.Answer;
import com.cymal.entity.po.subject.AbstractSubject;
import com.cymal.entity.po.subject.BlankSubject;
import com.cymal.entity.po.subject.JudgeSubject;
import com.cymal.search.Searcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 填空题搜寻器
 */
@Component
public class BlankSearcher implements Searcher<BlankSubject> {


    /**
     * Redis模板
     */
    @Autowired
    private RedisTemplate<String, List<Answer>> redisTemplate;


    /**
     * 搜寻
     * @param subject 题目.
     * @return 答案.
     */
    @Override
    public List<Answer> search(BlankSubject subject) {
        var key = subject.key();
        List<Answer> answers = redisTemplate.opsForValue().get(key);
        return answers;
    }


    /**
     * 搜寻类型
     * @return 搜寻类型
     */
    @Override
    public AbstractSubject.SubjectType searchType() {
        return AbstractSubject.SubjectType.judge;
    }


}
